import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

createApp(App).use(store).use(router).mount("#app");

import { CbEvents, OpenIMSDK } from "open-im-sdk";

const OpenIM = new OpenIMSDK();

const config = {
  userID: "openIMAdmin",
  platformID: 5,

  // token:"",
  // wsAddr: "wss://172.27.157.18/ws",
  // apiAddr: "https://172.27.157.18/openim/",
  token:
    "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiJvcGVuSU1BZG1pbiIsIlBsYXRmb3JtSUQiOjUsImV4cCI6MTcxNDMxMzYxNSwibmJmIjoxNzA2NTM3MzE1LCJpYXQiOjE3MDY1Mzc2MTV9.KRk1lSLETD2HS8XYHZpT6zWO3qSdWBHDW1pQFNOwEHU",
  wsAddr: "wss://192.168.1.127/ws",
  apiAddr: "https://192.168.1.127/openim/",

  // token:
  //   "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiJvcGVuSU1BZG1pbiIsIlBsYXRmb3JtSUQiOjUsImV4cCI6MTcxNDMxMzM4MSwibmJmIjoxNzA2NTM3MDgxLCJpYXQiOjE3MDY1MzczODF9.vmaSBnLmwOkJtxUg0TOXfpsbNyppFWLpg6JEBhFeBXk",
  // wsAddr: "wss://192.168.1.10/immini",
  // apiAddr: "https://192.168.1.10/imapi",
};
OpenIM.login(config)
  .then(async () => {
    // 登录成功
    console.log("登录成功...");

    OpenIM.getSelfUserInfo()
      .then(({ data }) => {
        // data: 当前登录用户的个人信息
        console.log(data);
      })
      .catch(({ errCode, errMsg }) => {
        // 调用失败
      });

    const message = (await OpenIM.createTextMessage("hello openim")).data;

    OpenIM.sendMessage({
      recvID: "openIMAdmin",
      groupID: "",
      message,
    })
      .then(() => {
        console.log("消息发送成功");
        // Message sent successfully ✉️
      })
      .catch((err) => {
        // Failed to send message ❌
        console.log(err);
      });
  })
  .catch(({ errCode, errMsg }) => {
    // 登录失败
    console.log("登录失败");
  });

OpenIM.on(CbEvents.OnConnectSuccess, () => {
  console.log("登录成功");
});
